<template>
  <view class="coach-detail-container">
    <view class="header-section">
      <text class="page-title">教练详情</text>
    </view>
    
    <view class="coach-detail-card">
      <image class="coach-avatar" :src="coachDetail.avatar || '/static/logo.png'" mode="aspectFill"></image>
      
      <view class="coach-info">
        <text class="coach-name">{{ coachDetail.name }}</text>
        <text class="coach-specialty">专长：{{ coachDetail.specialty }}</text>
        <text class="coach-experience">{{ coachDetail.experience }}年教学经验</text>
        
        <view class="coach-meta">
          <view class="meta-item">
            <text class="meta-label">性别：</text>
            <text class="meta-value">{{ coachDetail.gender }}</text>
          </view>
          <view class="meta-item">
            <text class="meta-label">联系电话：</text>
            <text class="meta-value">{{ coachDetail.phone }}</text>
          </view>
          <view class="meta-item">
            <text class="meta-label">邮箱：</text>
            <text class="meta-value">{{ coachDetail.email }}</text>
          </view>
          <view class="meta-item">
            <text class="meta-label">证书：</text>
            <text class="meta-value">{{ coachDetail.certificate }}</text>
          </view>
        </view>
        
        <text class="coach-description">{{ coachDetail.description }}</text>
      </view>
    </view>
    
    <view class="action-section">
      <button class="back-button" @click="goBack">返回</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { coachApi } from '../../src/services/coach'

// 教练详情数据
const coachDetail = ref({
  id: 0,
  name: '',
  specialty: '',
  experience: 0,
  gender: '',
  phone: '',
  email: '',
  certificate: '',
  avatar: '/static/logo.png',
  description: '',
  status: 1
})

// 页面加载时获取教练详情
onMounted(() => {
  // 从路由参数获取教练ID
  const pages = getCurrentPages()
  const current = pages[pages.length - 1]
  const options = current.options || {}
  const coachId = options.id ? parseInt(options.id) : 1
  fetchCoachDetail(coachId)
})

// 获取教练详情
const fetchCoachDetail = async (id: number) => {
  try {
    const response: any = await coachApi.getCoachDetail(id)
    coachDetail.value = response.data
  } catch (error) {
    console.error('获取教练详情失败:', error)
    uni.showToast({
      title: '获取教练详情失败',
      icon: 'none'
    })
  }
}

// 返回上一页
const goBack = () => {
  uni.navigateBack()
}
</script>

<style lang="scss" scoped>
.coach-detail-container {
  min-height: 100vh;
  background-color: #FFFFFF;
  padding: 20rpx;
}

.header-section {
  background-color: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
  border-radius: 10rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  
  .page-title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
    text-align: center;
  }
}

.coach-detail-card {
  background-color: #fff;
  border-radius: 10rpx;
  padding: 30rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.coach-avatar {
  width: 200rpx;
  height: 200rpx;
  border-radius: 100rpx;
  margin: 0 auto 30rpx;
  display: block;
}

.coach-info {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.coach-name {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  text-align: center;
}

.coach-specialty {
  font-size: 28rpx;
  color: #4B0082;
  text-align: center;
}

.coach-experience {
  font-size: 28rpx;
  color: #666;
  text-align: center;
}

.coach-meta {
  display: flex;
  flex-direction: column;
  gap: 15rpx;
  margin: 20rpx 0;
}

.meta-item {
  display: flex;
}

.meta-label {
  font-size: 28rpx;
  color: #666;
  width: 150rpx;
}

.meta-value {
  font-size: 28rpx;
  color: #333;
  flex: 1;
}

.coach-description {
  font-size: 28rpx;
  color: #333;
  line-height: 1.5;
  margin-top: 20rpx;
  padding-top: 20rpx;
  border-top: 2rpx solid #f5f5f5;
}

.action-section {
  padding: 0 20rpx;
}

.back-button {
  background-color: #4B0082;
  color: #fff;
  border: none;
  padding: 30rpx;
  border-radius: 10rpx;
  font-size: 32rpx;
  width: 100%;
}
</style>